package com.service.admin.borrow.controller;

import com.service.admin.base.controller.req.SysFILConfigPageReq;
import com.service.admin.base.service.SysFilConfigService;
import com.service.admin.borrow.controller.req.SysBorrowPageRequest;
import com.service.admin.borrow.service.SysBorrowConfigService;
import com.service.admin.framework.log.RequestLog;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.model.SysBorrowConfig;
import com.service.dao.model.SysFilConfig;
import com.service.utility.common.UUIDUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController()
@Api(tags = "借贷系统配置")
@RequestMapping("sys-borrow")
public class SysBorrowController extends BaseController {
    @Autowired
    private SysBorrowConfigService borrowConfigService;

    @ApiOperation("借贷配置信息列表")
    @RequestLog("借贷配置信息列表")
    @PostMapping("list")
    public PageResponse<SysBorrowConfig> list(@ApiParam @RequestBody SysBorrowPageRequest req){
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", req, uuid);
        log.info("请求结束： UUID:{}", uuid);
        return successQueryPageResponse(borrowConfigService.pageLastBorrowConfig(req));
    }

    @ApiOperation("新增借贷配置记录")
    @RequestLog("新增借贷配置记录")
    @PostMapping("create")
    public BaseResponse create(@ApiParam @RequestBody SysBorrowConfig config){
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", config, uuid);
        borrowConfigService.save(config);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @ApiOperation("修改借贷配置记录")
    @RequestLog("修改借贷配置记录")
    @PostMapping("modify")
    public BaseResponse modify(@ApiParam @RequestBody SysBorrowConfig config){
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", config, uuid);
        borrowConfigService.updateById(config);
        log.info("请求结束： UUID:{}", uuid);
        return successUpdateBaseResponse();
    }

}
